/*
 * Copyright 2013 Agustina Martinez-Garcia

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */
package uk.ljmu.metadata.staticschemas;

import java.io.InputStream;

import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.Resource;

public class GeoSchema {
	 /** <p>The RDF model that holds the vocabulary terms</p> */
    private static Model m_model = ModelFactory.createDefaultModel();
    
    /** <p>The namespace of the vocabulary as a string</p> */
    public static final String NS = "http://www.w3.org/2003/01/geo/wgs84_pos#";
    
    /** <p>The namespace of the vocabulary as a string</p>
     *  @see #NS */
    public static String getURI() {return NS;}
    
    /** <p>The namespace of the vocabulary as a resource</p> */
    public static final Resource NAMESPACE = m_model.createResource( NS );
    
    /** <p>The WGS84 altitude of a SpatialThing (decimal meters above the local reference 
     *  ellipsoid).</p>
     */
    public static final Property alt = m_model.createProperty( "http://www.w3.org/2003/01/geo/wgs84_pos#alt" );
    
    /** <p>The WGS84 latitude of a SpatialThing (decimal degrees).</p> */
    public static final Property lat = m_model.createProperty( "http://www.w3.org/2003/01/geo/wgs84_pos#lat" );
    
    /** <p>A comma-separated representation of a latitude, longitude coordinate.</p> */
    public static final Property lat_long = m_model.createProperty( "http://www.w3.org/2003/01/geo/wgs84_pos#lat_long" );
    
    /** <p>The relation between something and the point, or other geometrical thing in 
     *  space, where it is. For example, the realtionship between a radio tower and 
     *  a Point with a given lat and long. Or a relationship between a park and its 
     *  outline as a closed arc of points, or a road and its location as a arc (a 
     *  sequence of points). Clearly in practice there will be limit to the accuracy 
     *  of any such statement, but one would expect an accuracy appropriate for the 
     *  size of the object and uses such as mapping .</p>
     */
    public static final Property location = m_model.createProperty( "http://www.w3.org/2003/01/geo/wgs84_pos#location" );
    
    /** <p>The WGS84 longitude of a SpatialThing (decimal degrees).</p> */
    public static final Property long_ = m_model.createProperty( "http://www.w3.org/2003/01/geo/wgs84_pos#long" );
    
    public static Model getModel()
    {
	ClassLoader classLoader = Thread.currentThread()
	.getContextClassLoader();
	InputStream is;
	is = classLoader.getResourceAsStream("geo.rdf");

    	Model myModel = ModelFactory.createDefaultModel();
    	
    	try {
    	    myModel.read(is, "");
    	    return myModel;
    	}catch (Exception ex) {
    	    return myModel;
    	}      
    }
    
    public static boolean containsProperty(String elementName) {
    	
    	if (elementName.contains(":"))
    		elementName = elementName.substring(elementName.indexOf(":") + 1);
    	if (!GeoSchema.alt.getLocalName().equals(elementName) &&
    		!GeoSchema.lat.getLocalName().equals(elementName) &&
    		!GeoSchema.lat_long.getLocalName().equals(elementName) &&
    		!GeoSchema.location.getLocalName().equals(elementName) &&
    		!GeoSchema.long_.getLocalName().equals(elementName))
    	return false;
    	else return true;
    }

}
